﻿<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Welcome extends CI_Controller
{
	public $data = array();
	private $pagetitle = array('首页', '赚积分', '我的推广', '规则', '用户授权', '提示信息');
	private $sen_data = array();
	function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->config->load('siteset', true);
		$this->data['siteset'] = $this->config->item('siteset');
		$this->sen_data        = $this->session->userdata('wb_userinfo');
		$params                = array(
            'client_id' => $this->data['siteset']['client_id'],
            'client_secret' => $this->data['siteset']['client_secret'],
            'access_token' => '',
            'refresh_token' => $this->data['siteset']['refresh_token']
		);
		$this->load->library('Sinaapi', $params);
		if (!empty($this->sen_data)) {
			$this->load->model('Mwbuser');
			$re = $this->Mwbuser->getinfo($this->sen_data['wb_id'], 'jifen,coins,profile_image_url');
			if (!empty($re)) {
				$this->sen_data['jifen']                            = $re['jifen'];
				$this->sen_data['coins']                         = $re['coins'];
				$this->sen_data['profile_image_url'] = $re['profile_image_url'];
			}
		} else {
			$this->sen_data['profile_image_url'] = '';
		}

	}
	/**
 * 
 * 通过mid获得短格式
 * @param string $mid
 * @return 短格式
 */
public function getCodeByMid($mid){
	$url = '';

	for ($i = strlen($mid) - 7; $i > -7; $i -=7)//从最后往前以7字节为一组读取mid
	{
		$offset1 = $i < 0 ? 0 : $i;
		$offset2 = $i + 7;
		$num = substr($mid, $offset1,$offset2-$offset1); 
		//mid.substring(offset1, offset2);

		$num = $this->int10to62($num);
		$url = $num .$url;
	}

	return $url;
}


/**
 * 10进制值转换为62进制
 * @param {String} int10 10进制值
 * @return {String} 62进制值
 */
public function int10to62($int10) {
	$str62keys = array(
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
	"a", "b", "c", "d", "e", "f", "g", "h", "i", 
	"j", "k", "l", "m", "n", "o", "p", "q", 
	"r", "s", "t", "u", "v", "w", "x", "y", 
	"z","A", "B", "C", "D", "E", "F", "G", "H", 
	"I", "J", "K", "L", "M", "N", "O", "P", 
	"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
);
	$s62 = '';
	$r = 0;
	while ($int10 != 0)
	{
		$r = $int10 % 62;
		$s62 = $str62keys[$r].$s62;
		$int10 = floor($int10 / 62);
	}
	return $s62;
}
	public function index()
	{
 
		
		$data['vote'] = $this->data['siteset'];
		$this->load->model('Mwbuser');
		if (!$this->session->userdata('wb_userinfo')) {
			$invite = $this->input->get('invite');

			if (!empty($invite) && is_numeric($invite)) {
				$this->session->set_userdata('cinvite', $invite);

			}
			$hearddata['refresh_token'] = $this->data['siteset']['refresh_token'];
			$hearddata['client_id']     = $this->data['siteset']['client_id'];
			
			$hearddata['sindex']        = $this->data['siteset']['sitename'] . '-' . $this->pagetitle[4];
			$this->load->view('auth_view', $hearddata);
			return '';
		} else {

		}
	
		$this->sen_data = $this->session->userdata('wb_userinfo');

		if ($this->sen_data['followers_count'] < $this->data['siteset']['followersCount_login_limits']) {
			header("content-type: text/html; charset=utf-8");
			show_error('因您的粉丝数不足' . $this->data['siteset']['followersCount_login_limits'] . '被系统限制登录。');
		}

		if ($this->sen_data['status'] == '1') {
			header("content-type: text/html; charset=utf-8");
			show_error('您的帐户已经被锁定，需要恢复请找QQ:583028985联系！');
		}

		$this->db->select('uid,nickname,touid,tonickname,types,datatime,points,coins,paytype,showtype');
		$this->db->from('wtt_pays');
		$this->db->where('paytype', 1);
		$this->db->where('(types=3 or types=5)');

		$this->db->order_by('datatime', 'desc');
		$this->db->limit(10, 0);
		$query = $this->db->get();

		$this->data['chongzhi'] = '';
		if ($query->num_rows() > 0) {
			foreach ($query->result_array() as $item) {

				if ($item['types'] == 3) {
					$this->data['chongzhi'] .= '  ' . $item['nickname'] . '<span style=\'color:#008000;\'><b>充值了</b></span><span style=\'color:#ff0000;\'>' . $item['points'] . '</span>积分' . ' <span style=\'color:#cccccc;\'>- ' . date('Y-n-j H:i:s', $item['datatime']) . '</span>';
				} else {
					$this->data['chongzhi'] .= '  ' . $item['nickname'] . '<span style=\'color:#008000;\'>邀请好友</span>' . $item['tonickname'] . '获取<span style=\'color:#ff0000;\'>' . $item['points'] . '</span>积分' . ' <span style=\'color:#cccccc;\'>- ' . date('Y-n-j H:i:s', $item['datatime']) . '</span>';
				}

			}
		}
		$this->db->select('uid,nickname,touid,tonickname,types,datatime,points,coins,paytype,showtype');
		$this->db->from('wtt_pays');
		$this->db->where('paytype', 1);
		$this->db->where('(types=3)');

		$this->db->order_by('points', 'desc');
		$this->db->limit(5, 0);
		$cz = $this->db->get();
		$cz_tj = $cz->result_array();
		 	
		$this->myview('welcome_message', $this->data);
	}
	/*
	 *授权绑定返回处理
	 */
	public function sinaband()
	{
		$code = $this->input->get('code');
		if (isset($code)) {
			$keys                 = array();
			$keys['code']         = $code;
			$keys['redirect_uri'] = $this->data['siteset']['refresh_token'];
			$token                = $this->sinaapi->getAccessToken('code', $keys);
			// var_dump($token);
			if ($token) {	
				if(empty($token['uid']))
				{
					redirect('/');
				}else{
					$this->load->model('Mwbuser');
					$re_info = $this->Mwbuser->setwbuser($token);
					if (isset($re_info['error'])) {
						$this->myview('error_view', $this->data);
						return false;
					} else {
						$this->session->set_userdata('wb_userinfo', $re_info);
						$this->sen_data = $this->session->userdata('wb_userinfo');
						redirect('welcome');
					}
				}
			} else {
				show_error('授权失败，请重试！');
			}

		} else {
			show_error('授权失败，请重试！');
		}
	}
	public function getpoints()
	{
		$this->chklogin();
		$action                          = $this->input->get('action');
		$this->data['siteset']['action'] = $action;
		$this->myview('getpoints_view', $this->data['siteset'], 1);
	}
	public function mytg()
	{
		$this->chklogin();
		$bb = $this->session->userdata('wb_userinfo');
		$this->load->model('Mfollow');
		$datas['follow']  = $this->Mfollow->get($bb['wb_id']);
		$datas['reposts'] = $this->Mfollow->getreposts($bb['wb_id']);
		$this->myview('mytg_view', $datas, 2);
	}
	public function siterules()
	{
		$this->chklogin();
		$this->myview('siterules_view', $this->data['siteset'], 3);
	}
	//TODO:创建关注任务
	function addfollowtask()
	{
		$this->chklogin();
		$bb  = $this->session->userdata('wb_userinfo');
		$arr = array(
            "status" => 0,
            "info" => '',
            "data" => ""
            );
            $this->load->model('Mwbuser');
            $uinfo = $this->Mwbuser->getinfo($bb['wb_id'], 'jifen');
            if ($uinfo['jifen'] < 10) {
            	$arr['info'] = '积分不足10不能使用，快去赚积分吧！';
            } else {
            	$this->load->model('Mfollow');
            	$arr['info'] = $this->Mfollow->insert($bb['wb_id']);
            	if (empty($arr['info'])) {
            		$arr['status'] = 1;
            	}
            }
            $this->exitjson($arr);
	}
	//TODO:转让积分
	function givepoints()
	{
		$this->chklogin();
		$bb = $this->session->userdata('wb_userinfo');

		$jifen    = $this->input->post('points');
		$nickname = $this->input->post('nickname');
		$arr      = array(
            "status" => 0,
            "info" => '',
            "data" => ''
            );
            $this->load->model('Mwbuser');

            $uinfo   = $this->Mwbuser->getinfo($bb['wb_id'], 'jifen');
            $touinfo = $this->Mwbuser->getinfobyscreen_name($nickname);

            //判断转让条件是否满足
            !is_array($touinfo) or (count($touinfo) == 0) and ($arr['info'] = "该昵称不存在.") and $this->exitjson($arr);
            ($uinfo['jifen'] < $this->data['siteset']['give_points_limits']) and ($arr['info'] = '您的积分不足' . $this->data['siteset']['give_points_limits'] . '不能使用转让功能，快去赚积分吧！') and $this->exitjson($arr);
            ($uinfo['jifen'] < $jifen) and ($arr['info'] = '积分不足，快去赚积分吧！') and $this->exitjson($arr);
            ($touinfo['wb_id'] == $bb['wb_id']) and ($arr['info'] = '不能转让给自己。') and $this->exitjson($arr);
            ($jifen < 1) and ($arr['info'] = '转让积分不能低于1分！') and $this->exitjson($arr);

            $this->Mwbuser->setpoints($touinfo['wb_id'], $jifen, $ptype = 1);
            $this->Mwbuser->insertlog($bb['wb_id'], $touinfo['wb_id'], $bb['screen_name'], 11, $jifen, 0, 2, 0);
            $this->Mwbuser->setpoints($bb['wb_id'], $jifen, $ptype = 0);
            $arr['status'] = 1;
            $arr['info']   = '转让积分成功';
            $this->exitjson($arr);
	}
	//TODO:兑换实物
	function exchangegoods()
	{
		$this->chklogin();
		$bb = $this->session->userdata('wb_userinfo');
		$goodsid = $this->input->post('goodsid');
		$arr = array(
            "status" => 0,
            "info" => '',
            "data" => ''
            );
            $this->load->model('Mwbuser');
            $uinfo     = $this->Mwbuser->getinfo($bb['wb_id']); //获取用户信息
            $goodsinfo = $this->Mwbuser->getinfo2($goodsid);  //获取商品信息
            $wb_id     = $uinfo['wb_id'];

            //判断粉币条件是否满足
            (intval($uinfo['coins']) < intval($goodsinfo['coins'])) and ($arr['info'] = '您的粉币不足' . $goodsinfo['coins'] . '不能兑换，快去赚粉币吧！') and $this->exitjson($arr);
            $this->Mwbuser->setcoins($wb_id, $goodsinfo['coins'], $ptype = 0);
            $this->load->model('Mexchange');
            $this->Mexchange->insertlog($wb_id, $goodsid, $goodsinfo['goods'], $goodsinfo['coins']);
            $arr['status'] = 1;
            $arr['info']   = '兑换成功';
            $this->exitjson($arr);
	}
	public function exitjson($arr)
	{
		if (!is_array($arr)) {
			$arr = array(
                "status" => 0,
                "info" => '',
                "data" => ''
                );
		}
		header("content-type: text/html; charset=utf-8");
		echo json_encode($arr);
		exit;
	}
	function getweibo()
	{
		$arr     = array(
            "status" => 0,
            "info" => "",
            "data" => ""
            );
            $feature = 0;
            if ($this->sen_data['followers_count'] < 100) { //粉丝数小于100 by:godok220
            	$feature = 1; //原创
            }
            $this->sinaapi->access_token = $this->sen_data['access_token'];
            $wb_c   = $this->sinaapi->user_timeline_by_id($this->sen_data['wb_id'], 1, 50, 0, 0, $feature);

            if (isset($wb_c['statuses']) && is_array($wb_c['statuses'])) {
            	$arr['status'] = 1;
            	$arr['data']   = "<div class='weibos'>";
            	$r             = '';
            	foreach ($wb_c['statuses'] as $item) {
            		$r .= "<div class='weibo' id='weibo_" . $item['mid'] . "'>";
            		$r .= '<input class=\'left radiofix\' type=\'checkbox\' value=\'' . $item['mid'] . '\' name=\'status_id\' id=\'status_id\' />';
            		$r .= "<div class='left' style='width:640px; margin-left:5px;'>";
            		$r .= "<p class='text'>" . $item['text'];
            		if (isset($item['thumbnail_pic']) && !empty($item['thumbnail_pic'])) {
            			$r .= '<br /><img src="' . $item['thumbnail_pic'] . '" />';
            		}
            		$r .= '</p>';
            		if (isset($item['retweeted_status']) && !empty($item['retweeted_status'])) {
            			$r .= '<div class="weibo_retweeted"><dd class="weibo_retweeted_arrow"><em class="weibo_retweeted_arrline">◆</em><span>◆</span>';
            			$r .= '</dd><p>';
            			if (isset($item['retweeted_status']['user'])) {
            				$r .= '<a href="http://weibo.com/' . $item['retweeted_status']['user']['profile_url'] . '" target="_blank">' . $item['retweeted_status']['user']['screen_name'] . '</a>：';
            			}
            			$r .= $item['retweeted_status']['text'];
            			if (!empty($item['retweeted_status']['thumbnail_pic'])) {
            				$r .= '<br /><img src="' . $item['retweeted_status']['thumbnail_pic'] . '" />';
            			}
            			$r .= '</p></div>';
            		}
            		$r .= "<p style='text-align:right; color: #999; font-size:12px;'>" . date('Y-n-j H:i:s', strtotime($item['created_at'])) . "</p><hr></div></div>";
            	}
            	$arr['data'] .= $r . '</div><div style=\'padding:2px 10px\'><a class="btn btn-primary" onclick= "this.disabled=true;">确定选择</a>&nbsp;&nbsp;&nbsp;<font color="#FF0000"> 不得出现“粉丝”2个字，禁止转发其他互粉应用、兼职，如若反复尝试系统将自动封号。</font></div>';
            } else {
            	$arr['info'] = '微博内容获取失败,请刷新或稍后再试！' . $wb_c['error'];
            }
            $this->exitjson($arr);
	}

	//TODO:添加转发任务
	function addreposttask()
	{
		$arr                         = array(
            "status" => 0,
            "info" => "",
            "data" => ""
            );
            $this->sinaapi->access_token = $this->sen_data['access_token'];
            $this->load->model('Mfollow');
            //及时获取用户积分
            $this->load->model('Mwbuser');
            $uinfo       = $this->Mwbuser->getinfo($this->sen_data['wb_id'], 'jifen');
            $arr['info'] = $this->Mfollow->insert_repost($this->sen_data['wb_id'], $uinfo['jifen']);
            if (empty($arr['info'])) {
            	$arr['status'] = 1;
            }
            $this->exitjson($arr);
	}

	//TODO:抽奖
	function prizes()
	{
		$this->load->model('Mprize');
		$datas          = array();
		$datas['p_sz']  = $this->Mprize->GetPrizest();
		$datas['plist'] = $this->Mprize->GetPrizeList(19);
		$this->myview('prizes_view', $datas, 2);
	}

	//TODO:兑换实物
	function exchange()
	{

		$this->load->model('Mexchange');
		$datas = array();
		$datas['plist'] = $this->Mexchange->GetExchangeList(19);
		$this->data['page_list'] = $this->Mexchange->GetExchange();
		$this->myview('exchange_view', $datas, 2);
	}
	//TODO:兑换操作
	//TODO:抽奖操作
	function getprize()
	{
		$arr = array(
            "status" => 0,
            "info" => "",
            "data" => ""
            );
            $this->load->model('Mprize');
            $r_s = $this->Mprize->GetPrize($this->sen_data['wb_id'], $this->sen_data['screen_name']);
            if ($r_s['error_info'] != '') {
            	$arr['info'] = $r_s['error_info'];
            } else {
            	$arr['status'] = 1;
            	$arr['data']   = $r_s['info'];
            }
            $this->exitjson($arr);
	}
	//TODO:修改关注
	function updatefollowg()
	{
		$arr = array(
            "status" => 0,
            "info" => "",
            "data" => ""
            );

            $tid     = $this->input->post('tid');
            $points  = $this->input->post('points');
            $max_num = $this->input->post('max_num');
            $fans    = $this->input->post('fans');
            $gender  = $this->input->post('gender');
            $this->load->model('Mfollow');
            $arr['info'] = $this->Mfollow->updatefollowg($this->sen_data['wb_id'], $tid, $points, $max_num, $fans, $gender);
            if (empty($arr['info'])) {
            	$arr['status'] = 1;
            }
            $this->exitjson($arr);
	}
	 
	//TODO:修改转发
	function updaterepostg()
	{
		$arr     = array(
            "status" => 0,
            "info" => "",
            "data" => ""
            );
            $tid     = $this->input->post('tid');
            $points  = $this->input->post('points');
            $max_num = $this->input->post('max_num');
            $fans    = $this->input->post('fans');
            $gender  = $this->input->post('gender');
            $this->load->model('Mfollow');
            $arr['info'] = $this->Mfollow->updaterepostg($this->sen_data['wb_id'], $tid, $points, $max_num, $fans, $gender);
            if (empty($arr['info'])) {
            	$arr['status'] = 1;
            }
            $this->exitjson($arr);
	}

	//TODO:设置状态
	function setactive()
	{
		$arr    = array(
            "status" => 0,
            "info" => "",
            "data" => ""
            );
            $tid    = $this->input->post('tid');
            $type   = $this->input->post('type');
            $active = $this->input->post('active');
            $this->load->model('Mfollow');
            $arr['info'] = $this->Mfollow->setactive($this->sen_data['wb_id'], $tid, $type, $active);
            if (empty($arr['info'])) {
            	$arr['status'] = 1;
            }
            $this->exitjson($arr);
	}
	//TODO:删除推广
	function deleteg()
	{
		$arr  = array(
            "status" => 0,
            "info" => "",
            "data" => ""
            );
            $tid  = $this->input->post('tid');
            $type = $this->input->post('type');
            $this->load->model('Mfollow');
            $arr['info'] = $this->Mfollow->deleteg($this->sen_data['wb_id'], $tid, $type);
            if (empty($arr['info'])) {
            	$arr['status'] = 1;
            }
            $this->exitjson($arr);
	}
	private function myview($pageview, $pagedata = '', $sindex = 0)
	{

		$jifen = $this->sen_data['jifen'];
		$coins = $this->sen_data['coins'];
		if (!$coins)  $coins = 0;
		$this->data['tuiguangs']   = $this->Mwbuser->gettuiguang($this->sen_data['wb_id']);
		$this->data['todatejifen'] = $this->Mwbuser->gettodata($this->sen_data['wb_id']);

		$usb                     = $this->Mwbuser->getinfo($this->sen_data['wb_id'], 'jifen');
		$this->sen_data['jifen'] = empty($usb['jifen']) ? 0 : $usb['jifen'];
		$jifen                   = $this->sen_data['jifen'];
		$coins = $this->sen_data['coins'];
		$this->data['jifen']     = $jifen;
		$this->data['coins']     = $coins;
		$this->data['fensi']     = $this->sen_data['screen_name'];
		$this->data['image_url'] = $this->sen_data['profile_image_url'];
		$hearddata['sindex']     = $this->data['siteset']['sitename'] . '-' . $this->pagetitle[$sindex];
		$hearddata['sindexn']    = $sindex;
		$hearddata['client_id']  = $this->data['siteset']['client_id'];
		$hearddata['wb_id']      = $this->sen_data['wb_id'];
		$hearddata['shardf']     = $this->data['siteset']['invite_points'];
		$hearddata['shardn']     = $this->data['siteset']['rt_validity'];
		$hearddata['fensi']      = $this->sen_data['screen_name'];
		$hearddata['jifen']      = $jifen;
		$hearddata['coins']      = $coins;
		$hearddata['fenxiang'] ="我刚用%23爱互粉%23%23互粉%23应用增加了很多真实的活跃粉丝，微博也有人转了，玩微博更带劲了， 你也想增加你的微博影响力吗？ 快来试试吧！".urlencode("http://www.aihufen.com/?invite=".$this->sen_data['wb_id']);
		$hearddata['image_url']  = $this->sen_data['profile_image_url'];
		@$hearddata['chongzhi'] = $this->data['chongzhi'];
		$w_info   = $this->Mwbuser->getinfo($this->sen_data['wb_id'], 'signin');
		$issignin = 1;
		if (!empty($w_info)) {
			$signintime = $w_info['signin'];
			if (date('y-n-j', $signintime) != date('y-n-j', time())) {
				$issignin = 0;
			}
		}
		$hearddata['issignin'] = $issignin;
		$this->load->view('heard_view', $hearddata);
		$this->load->view('page_left_view', $this->data);
		$this->load->view($pageview, $pagedata);
		//$this->load->view('page_right_view',$right_data);

	}

	//TODO:获取关注列表
	function followtuis()
	{
		$arr  = array(
            "status" => 0,
            "info" => "",
            "data" => array(
                'body' => '',
                'count' => 0,
                'page_size' => 12
		)
		);
		$p    = $this->uri->segment(3);
		$pe   = $this->uri->segment(4);
		$city = $this->uri->segment(5);
		$this->load->model('Mfollow');
		$getfs = $this->Mfollow->followtuis($this->sen_data, $p, $pe, $city);
		if (is_array($getfs)) {
			$arr['status']       = 1;
			$arr['data']['body'] = "<div class='fusers clearfix'>";
			if (!empty($getfs)) {
				$this->load->model('Mwbuser');
				$toinfo = $this->Mwbuser->getinfo($this->sen_data['wb_id'], 'gender,verified,verified_type,verified_reason,followers_count');
				//$arr['data']['count'] =  $this->Mfollow->tuoguangnum($this->sen_data['wb_id'],$pe,$city,$toinfo['gender'],$toinfo['followers_count']);
				$i      = 1;
				
				foreach ($getfs as $item) {
					$arr['data']['body'] .= "<div class='fuser left'>";
					
					$arr['data']['body'] .= "<a href=\"http://weibo.com/u/" . $item['uid'] . "\" target=\"_blank\">" ."<img src=\"" . $item['avatar_large'] . "\" width='112' height='112'>";
					$arr['data']['body'] .= "<p>";				
						$arr['data']['body'] .=  $item['screen_name'];
						if ($item['verified'] && $item['verified_type'] != '6' && $item['verified_type'] != '2' )                $arr['data']['body'] .= "<i title='微博个人认证 ' class='W_ico16 approve'></i>";
						if (($item['verified_type'] == '6' )|| ($item['verified_type'] == '2'))  $arr['data']['body'] .= "<i title='微博机构认证'  class='W_ico16 approve_co'></i>";
				 	   	if (($item['verified_type'] == '220') || ($item['verified_type'] == '200'))	$arr['data']['body'] .= "<i node-type='daren' class='W_ico16 ico_club' title='微博达人'></i>";
					 	$arr['data']['body'] .= "<br>";
					$arr['data']['body'] .= "</p></a><p style='white-space:nowrap;'>" . $item['location'] . "</p><p style='color:#FF6600;'>";
					//$arr['data']['body'] .= "<a class=' btn btn-danger' onclick='btn(".$item['uid'].",\"http://weibo.com/u/" . $item['uid'] . "\",".$item['follow_points'].")' sid='" . $item['uid'] . "' href='javascript:;' style='padding:2px 16px;' \">";
					$arr['data']['body'] .= "<a class='btn btn-danger' href='javascript:;' style='padding:2px 16px;' onclick=\"guanzhu(" . $item['uid'] . ", this);\" >关注</a>
					<a id='lq_".$item['uid']."' class='btn btn-danger' style='display:none' href='javascript:;' style='padding:2px 16px;' onclick=\"tu_follow(" . $item['uid'] . ", this);\">领 取</a>
					
					&nbsp;获" . $item['follow_points'] . "分</p></div>";
					$i++;

				} 
				$arr['data']['count'] = $i;
			} else {
				$arr['data']['count'] = 0;
				$arr['data']['body'] .= "没有记录了";
			}
			$arr['data']['body'] .= "</div>";
		} else {
			$arr['info'] = $getfs;
		}
		header("content-type: text/html; charset=utf-8");
		echo json_encode($arr);
	}
	//TODO:右侧推荐
	function tfollowtuis()
	{
		$arr  = array(
            "status" => 0,
            "info" => "",
            "data" => array(
                'body' => '',
                'count' => 0,
                'page_size' => 5
		)
		);
		$p    = $this->uri->segment(3);
		$pe   = $this->uri->segment(4);
		$city = $this->uri->segment(5);
		$this->load->model('Mfollow');
		$getfs = $this->Mfollow->followtuis($this->sen_data, $p, $pe, $city, 3, 1);
		if (is_array($getfs)) {
			$arr['status']       = 1;
			$arr['data']['body'] = "<div class='fusers clearfix'>";
			if (!empty($getfs)) {
				$this->load->model('Mwbuser');
				$toinfo = $this->Mwbuser->getinfo($this->sen_data['wb_id'], 'gender,followers_count');
				//$arr['data']['count'] =  $this->Mfollow->tuoguangnum($this->sen_data['wb_id'],$pe,$city,$toinfo['gender'],$toinfo['followers_count']);
				$i      = 1;
//<a class='btn btn-danger' href='javascript:;' style='padding:2px 16px;' onclick=\"tu_tfollows(" . $item['uid'] . ", this);\">领取</a>
				foreach ($getfs as $item) {
					$arr['data']['body'] .= "<div class='special_user clearfix' ><div class='left' style='width:50px'>";
					$arr['data']['body'] .= "<a href=\"http://weibo.com/u/" . $item['uid'] . "\" target=\"_blank\" style='color:#0088cc;'><img src=\"" . $item['avatar_large'] . "\" width='50' /></a></div>";
					$arr['data']['body'] .= "<div class='left' style='margin-left:8px;_margin-left:3px;overflow:hidden;' >";
					$arr['data']['body'] .= "<p style='white-space:nowrap;width:50px'><a href=\"http://weibo.com/u/" . $item['uid'] . "\" target=\"_blank\" style='color:#0088cc;'>" . $item['screen_name'] . "</a></p>";
					$arr['data']['body'] .= "<p style='color:#FF6600; margin-top:8px;'>
					<a class='btn btn-danger' href='javascript:;' style='padding:2px 16px;' onclick=\"guanzhu(" . $item['uid'] . ", this);\" >关注</a>
					<a id='lq_".$item['uid']."' class='btn btn-danger' style='display:none' href='javascript:;' style='padding:2px 16px;' onclick=\"tu_tfollows(" . $item['uid'] . ", this);\">领 取</a>
					<span>&nbsp;" . $item['follow_points'] . "分</span></p></div></div></div></div>";

				}
				$arr['data']['count'] = $i;
			} else {
				$arr['data']['count'] = 0;
				$arr['data']['body'] .= "充值你就会显示在这里";
			}
			$arr['data']['body'] .= "</div>";
		} else {
			$arr['info'] = $getfs;
		}
		header("content-type: text/html; charset=utf-8");
		echo json_encode($arr);
	}

	/*
	 * 获取转发列表
	 *
	 */
	function reposttuis()
	{
		$arr      = array(
            "status" => 0,
            "info" => "",
            "data" => array(
                'body' => '',
                'count' => 0,
                'page_size' => 6
		)
		);
		$p        = $this->uri->segment(3);
		$pe       = $this->input->post('province');
		$city     = $this->input->post('city');
		$showtype = $this->input->post('showtype');
		$this->load->model('Mfollow');
		$getfs = $this->Mfollow->reposttuis($this->sen_data, $p, $pe, $city, 6, $showtype);
		if (is_array($getfs)) {
			$arr['status']       = 1;
			$arr['data']['body'] = "<div class='reposts'>\r\n\t\t";
			if (!empty($getfs)) {
				$this->load->model('Mwbuser');
				$toinfo = $this->Mwbuser->getinfo($this->sen_data['wb_id'], 'gender,followers_count');
				//$arr['data']['count'] =  $this->Mfollow->tuoguangnum($this->sen_data['wb_id'],$pe,$city,$toinfo['gender'],$toinfo['followers_count'],1);
				$i      = 1;
				foreach ($getfs as $item) {
					$arr['data']['body'] .= "<div class='repost clearfix'>\r\n\t\t";
					$arr['data']['body'] .= "<div class='left' style='width:50px'>\r\n\t\t";
					$arr['data']['body'] .= "<img src=\"" . $item['profile_image_url'] . "\" width='42' height='42' />\r\n\t\t</div>\r\n\t\t";

					$arr['data']['body'] .= "<div class='left content'>\r\n\t\t<p>";
					$arr['data']['body'] .= "<a class='fbold' href=\"http://weibo.com/u/" . $item['uid'] . "\" style='color:#0088cc;' target=\"_blank\">" . $item['screen_name'] . "</a>";
					$arr['data']['body'] .= "<span>" . $this->format_text($item['wb_text']) . "</span></p>";
					if (!empty($item['thumbnail_pic'])) {
						$arr['data']['body'] .= "<img src=\"" . $item['thumbnail_pic'] . "\" height='80' />\r\n\t\t";
					}
					if (!empty($item['r_text'])) {
						$arr['data']['body'] .= "<div class=\"weibo_retweeted\">";
						$arr['data']['body'] .= "<dd class=\"weibo_retweeted_arrow\">";
						$arr['data']['body'] .= "<em class=\"weibo_retweeted_arrline\">◆</em><span>◆</span></dd><p>";
						$arr['data']['body'] .= "<a  href=\"http://weibo.com/u/" . $item['r_uid'] . "\" style='color:#0088cc;' target=\"_blank\">" . $item['r_name'] . "</a>:";
						$arr['data']['body'] .= $this->format_text($item['r_text']) . "</p>";
						if (!empty($item['r_pic'])) {
							$arr['data']['body'] .= "<img src=\"" . $item['r_pic'] . "\" height='80' />";
						}
						$arr['data']['body'] .= "</div>";
					}
					$reason  = '';
					$reasons = json_decode($item['reasons_json']);
					if ($reasons != NULL) {
						$arr_randnum = rand(0, count($reasons) - 1);
						$reason      = $reasons[$arr_randnum];
					}
		
					$arr['data']['body'] .= "<div style='color:#FF6600; text-align:right;' class='mt10 clearfix'><!--<span class='time left'>" . date('Y-n-j H:i:s', $item['datetime']) . "</span>-->";
					$arr['data']['body'] .= "<span style='_margin-left:3px;' class='time left'><span style='color:#777'>默认转发理由：</span><input type='text' readonly='readonly' value='" . $reason . "' style='color:#888;border:0px;width:280px;*width:280px;' id='set_reason_" . $item['id'] . "'></span></span>";

					$arr['data']['body'] .= "<span class='right'>
					<a id=\"repost_" . $item['id'] . "\" class='btn btn-primary' href='javascript:;' style='padding:3px 20px;display:none' onclick='this.disabled=true;'>领取</a>&nbsp;&nbsp;
					
					<a class='btn btn-primary'  href='javascript:void(0);' target='new' style='padding:3px 20px;'  onclick=\"zhuanfa(" . $item['id'] . ",'".$this->getCodeByMid($item['status_id'])."',this,".$item['uid'].");\" >转发</a>
					
					&nbsp;可获得" . $item['rp_points'] . "分</span>";
					$arr['data']['body'] .= "</div></div></div>";
					$i++;
				}
				$arr['data']['count'] = $i;
			} else {
				$arr['data']['count'] = 0;
				$arr['data']['body'] .= "没有微博记录了。";
			}
			$arr['data']['body'] .= "</div>";
		} else {
			$arr['info'] = $getfs;
		}
		$this->exitjson($arr);
	}

	function format_text($text, $type = 'feed', $uid = 0, $show_em = true)
	{
		if (empty($text)) {
			return $text;
		}
		if ($type == 'feed') {

			// 短链配置
			static $shortLink = null;
			if (null == $shortLink) {
				$shortLink = '';
			}

			$newText = '';
			//$c = preg_quote("\"~!@#$%^&*()+`{}[]:'<>?,/|\`·#￥%…—*（）——+－＝：“；‘《》？，。、｜\\");//[^@\.\s\;".$c."]
			$mc      = preg_split(";(#[^#]+#|[a-z0-9\-_]*[a-z0-9]@(?:[a-z0-9-]+)(?:\.[a-z0-9-]+)+|@[\x{4e00}-\x{9fa5}0-9A-Za-z_\-]+|http://(?:sinaurl|t)\.cn/[a-z0-9]+|<a\s+href=[\"'][^\"']+[\"'][^>]*>.+?</a>);sium", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
			//print_r($mc);
			foreach ($mc as $i => $v) {
				if ($i % 2 == 1) {
					if (preg_match("#^http://(?:sinaurl|t)\.cn/[a-z0-9]+\$#sim", $v)) {
						// 短链替换
						if ($shortLink) {
							$v = preg_replace("#^http://(?:sinaurl|t)\.cn#sim", $shortLink, $v);
						}
						$newText .= ' <a title="' . $v . '" href="' . $v . '" target="_blank">' . $v . '</a> ';

					} else {
						$newText .= htmlspecialchars($v);
					}
				} else {
					$newText .= htmlspecialchars($v);
				}
			}
			$text = $newText;
		} else {
			$text = htmlspecialchars($text);
		}
		return $text;
	}

	//TODO:添加关注
	function dofollow()
	{
		$DB1   = $this->load->database('update', TRUE);
		$arr   = array(
            "status" => 0,
            "info" => "",
            "data" => ""
            );
            $touid = $this->input->post('sid');
            $this->load->model('Mfollow');
            $arr['info'] = $this->Mfollow->dofollow($this->sen_data['wb_id'], $touid, $this->data['siteset']['follow_limits_per_hour'], $this->data['siteset']['follow_limits_per_day']);
            if (empty($arr['info'])) {
            	$this->sinaapi->access_token = $this->sen_data['access_token'];
            	//$wb_c                        = $this->sinaapi->follow_by_id($touid);
				 $wb_c                        = $this->sinaapi->is_followed_by_id($touid);
				    
					
            	if (isset($wb_c['error']) || !empty($wb_c['error'])) {
            		$this->config->load('apierror', TRUE);
            		$errinfo = $this->config->item($wb_c['error_code'], 'apierror');
            		if (!$errinfo)
            		$errinfo = '未知错误1';
            		$arr['info'] = $errinfo;
            		//写入已经关注的例外信息20506已关注
            		if ($wb_c['error_code'] == '20506') {
            			$this->Mfollow->insert_hasfls($this->sen_data['wb_id'], $touid);
            		}

            		//判断用户不存在时关闭被关注人的推广
            		if ($wb_c['error_code'] == '20003' || $wb_c['error_code'] == '10013' || $wb_c['error_code'] == '20501') {
            			$DB1->query("update wtt_repost set rp_status=0 where uid='" . $touid . "'");
            			$DB1->query("update wtt_follow set follow_status=0 where uid='" . $touid . "'");
            			$DB1->query("DELETE from wtt_autos where wb_id='" . $touid . "'");
            		}
            	} else {
					if($wb_c['target']['followed_by'] ==true){
            		$this->load->model('Mwbuser');
            		/*
            		 //关注成功进行检查是否初始积分
            		 if($this->sen_data['jifen'] == $this->data['siteset']['reg_give_points'])
            		 {
            		 //进行推荐计算 $this->data['siteset']['invite_points']
            		 $this->Mwbuser->tuijians($this->sen_data['wb_id'],$this->data['siteset']['invite_points'],粉币);
            		 }
            		 */
            		$toinfo = $this->Mfollow->get($touid);
            		if (empty($toinfo))
            		$arr['info'] = '获取被关注列表错误';
            		$follow_points = $toinfo['follow_points']; //被关注用户设置的奖励积分
            		$toinfo = $this->Mwbuser->setpoints($touid, $follow_points, 2);  //被关注减去相应积分
            		if (!$toinfo)   $arr['info'] = '更新积分错误';
            		$this->Mfollow->setnum($touid, 0);  //设置推广点击数
            		$this->Mwbuser->sys_give($this->sen_data['wb_id'],$touid,$this->sen_data['screen_name'],1,$this->data['siteset']['follow_points'],$this->data['siteset']['follow_coins']);//系统给的            		
            		$toinfo =( $this->Mwbuser->setpoints($this->sen_data['wb_id'], ($follow_points - 1), 1)); //用户应得
            		if (!$toinfo)   $arr['info'] = '更新积分错误';
            		$this->Mwbuser->insertlog($this->sen_data['wb_id'], $touid, $this->sen_data['screen_name'], 1, $follow_points-1,0,1);
            		$this->Mwbuser->insetchkpay($this->sen_data['wb_id'], $touid, 0, 0, 1, $follow_points);
            		$arr['data']   = $follow_points - 1;
            		$arr['status'] = 1;
            		$arr['info'] = '关注成功，您获得<span style="color:red;" class="fbold">'.($follow_points - 1).'</span>分,系统赠送<span style="color:red;" class="fbold">'.$this->data['siteset']['follow_points'].'</span>积分和<span style="color:red;" class="fbold">'.$this->data['siteset']['follow_coins'].'</span>粉币';
            		 }
					 else{
					 $arr['data']   = "";
						$arr['status'] = 0;
						$arr['info'] = "请先关注";
					 }
            	}
            }
            $this->exitjson($arr);
	}
	/*
	 * 设置转发
	 *
	 */
	function dorepost()
	{
				
		$arr = array(
            "status" => 0,
            "info" => '',
            "data" => ""
            );
			 
            $status_id  = $this->input->post('status_id');
            $reason     = $this->input->post('reason');
            $is_comment = $this->input->post('is_comment');
            $this->load->model('Mfollow');
            $arr['info'] = $this->Mfollow->dorepost($this->sen_data['wb_id'], $status_id, $reason, $is_comment, $this->data['siteset']['rt_limits_per_hour'], $this->data['siteset']['rt_limits_per_day']);
            if (empty($arr['info'])) {
            	$toinfo = $this->Mfollow->get($status_id, 1);
            	if (empty($toinfo))
            	$arr['info'] = '获取推广列表错误';
            	$rp_points                   = $toinfo['rp_points'];
            	$touid                       = $toinfo['uid'];
            	$wb_cid                      = $toinfo['status_id'];
            	$this->sinaapi->access_token = $this->sen_data['access_token'];
				 
            //	$wb_c                        = $this->sinaapi->repost($toinfo['status_id'], $reason, $is_comment);
				$wb_c                        = $this->sinaapi->repost_timeline($this->sen_data['wb_id']);
				 
				$mid = empty($wb_c['statuses'][0]['retweeted_status']['mid'])?"":$wb_c['statuses'][0]['retweeted_status']['mid'];
				
				$idstr =empty($wb_c['statuses'][0]['retweeted_status']['user']['idstr'])?"":$wb_c['statuses'][0]['retweeted_status']['user']['idstr'];
			
            	if (isset($wb_c['error']) || !empty($wb_c['error'])) {
            		$this->config->load('apierror', TRUE);
            		$errinfo = $this->config->item($wb_c['error_code'], 'apierror');
            		if (!$errinfo) {
            			$errinfo = '' . $wb_c['error_code'] . '错误,请选择其他内容'; //如果发生错误暂定推广
            			$this->Mfollow->setactive($touid, $status_id, 1, 0);
            		} else if ($wb_c['error_code'] == '20101' || $wb_c['error_code'] == '20120' || $wb_c['error_code'] == '20132' || $wb_c['error_code'] == '21602') { //不存在、可见性、无法查看、敏感词
            			$this->Mfollow->setactive($touid, $status_id, 1, 0);
            		}
            		$arr['info'] = $errinfo;

            	} else {
				
				if($mid != $toinfo['status_id'] || $idstr != $toinfo['uid'])
				{
					$arr['info'] = '请先转发！';
				}
				else{
						$this->load->model('Mwbuser');
						$toinfo = $this->Mwbuser->setpoints($touid, $rp_points, 2);
						if (!$toinfo)
						$arr['info'] = '更新积分错误';
						$this->Mfollow->setnum($status_id, 1);
						$toinfo = $this->Mwbuser->setpoints($this->sen_data['wb_id'], ($rp_points - 1), 1);
						if (!$toinfo)
						
						$arr['info'] = '更新积分错误';
						
						
						$this->Mwbuser->insertlog($this->sen_data['wb_id'], $touid, $this->sen_data['screen_name'], 2, $rp_points, 0);
					
					 
						$this->Mwbuser->insetchkpay($this->sen_data['wb_id'], $touid, $status_id, $mid, 2, $rp_points);
						$arr['status'] = 1;
						
						$arr['data']   = $rp_points - 1;
						
						
						
							
							
						$todayrepostcount=$this->Mwbuser->gettodaydorepostcount($this->sen_data['wb_id']) ;
							
						
						if( $todayrepostcount > $this->data['siteset']['rt_limits_coins_day'] )
						{
							$arr['info'] = '转发成功，您获得<span style="color:red;" class="fbold">'.($rp_points - 1).'</span>分'.'，今日已转发'.$todayrepostcount.'条';
						}
						else {
							$this->Mwbuser->sys_give($this->sen_data['wb_id'],$touid,$this->sen_data['screen_name'],2,$this->data['siteset']['rt_points'],$this->data['siteset']['rt_coins']);//系统给的
							$arr['info'] = '转发成功，您获得<span style="color:red;" class="fbold">'.($rp_points - 1).'</span>分,系统赠送<span style="color:red;" class="fbold">'.$this->data['siteset']['rt_points'].'</span>积分和<span style="color:red;" class="fbold">'.$this->data['siteset']['rt_coins'].'</span>粉币'.'，今日已转发'.$todayrepostcount.'条';
						}
            		}
            	}
            }
            $this->exitjson($arr);
	}
	/*
	 *
	 */


	//TODO:邀请分享
	function dopost()
	{
		$arr     = array(
            "status" => 0,
            "info" => "",
            "data" => ""
            );
            $content = $this->input->post('content');
            $action = $this->input->post('action');
            $this->load->model('Mwbuser');
            $this->sinaapi->access_token = $this->sen_data['access_token'];
             
            $arr['info']                 = $this->Mwbuser->dopost($this->sen_data, $content,$action);
            if (empty($arr['info'])) {
            	$arr['status'] = 1;
            	$this->Mwbuser->sys_give($this->sen_data['wb_id'],0,$this->sen_data['screen_name'],4,$this->data['siteset']['share_points'],$this->data['siteset']['share_coins']); 
            	$arr['data']   = '分享成功您获取'.$this->data['siteset']['share_points'].'积分,'.$this->data['siteset']['share_coins'].'粉币';				
            }
            $this->exitjson($arr);
	}
	/*
	 * 全部日志列表
	 */
	function alllogs()
	{                           //1，关注，2转发 ，3 充值,4,分享 ，5邀请好友,6违规，7，违规返还  8,签到 9，抽奖 10,兑换实物 ,11 转让积分
		$str_arr = array('',  '关注',   '转发',   '充值', '分享',    '邀请好友',  '违规',  '违规返还',  '签到',   '幸运抽奖',  '兑换实物','转让积分' );
		$this->db->select('uid,touid,nickname,tonickname,types,datatime,points,coins,paytype,showtype');
		$this->db->from('wtt_pays');
		$this->db->where('paytype', 1);
		$this->db->order_by('datatime', 'desc');
		$this->db->limit(30);
		$query = $this->db->get();
		$rs    = $query->result_array();
		$etext = '';
		foreach ($rs as $row) {
			$etext .= '<div class="log clearfix hide">';
			if ($row['types'] != '7') {
				$etext .= "<div class=\"left\" style='font-size:14px;'><a href='http://weibo.com/u/" . $row['uid'] . "' style='color:#0088cc;' target='_blank'>" . $row['nickname'];
				$etext .= '</a>' . $str_arr[$row['types']] . "<a href='http://weibo.com/u/" . $row['touid'] . "' style='color:#FF6600;' target='_blank'>" . $row['tonickname'] . "</a>";
				$etext .= "，&nbsp;&nbsp;<span style='color:#008000;' class='fbold'>+" . $row['points'] . "</span></div>";
			} else {
				$etext .= "<div class=\"left\" style='font-size:14px;'><a href='http://weibo.com/u/" . $row['touid'] . "' style='color:#0088cc;' target='_blank'>" . $row['tonickname'];
				$etext .= '</a>' . $str_arr[$row['showtype']] . $str_arr[$row['types']] . "给<a href='http://weibo.com/u/" . $row['uid'] . "' style='color:#FF6600;' target='_blank'>" . $row['nickname'] . "</a>";
				$etext .= "，&nbsp;&nbsp;<span style='color:#008000;' class='fbold'>+" . $row['points'] . "</span></div>";
			}
			$etext .= "<div class='right'><span style='color:#999;font-size:13px;'>" . date('Y-n-j H:i:s', $row['datatime']) . "</span></div></div>";
		}
		echo $etext;
	}
	function mylogs()
	{

		$arr   = array(
            "status" => 0,
            "info" => "",
            "data" => array(
                'body' => '',
                'count' => 0,
                'page_size' => 10
		)
		);
		$p     = $this->uri->segment(3);
		$ptype = $this->uri->segment(4);
		$this->load->model('Mwbuser');
		$logs    = $this->Mwbuser->getlogs($this->sen_data['wb_id'], $p, $ptype);

		$str_arr = array('',  '关注',   '转发',   '充值', '分享',    '邀请好友',  '违规',  '违规返还',  '签到',   '幸运抽奖',  '兑换实物','转让积分' );

		if (is_array($logs)) {
			$arr['status'] = 1;
			if (!empty($logs)) {
				$r = '';

				foreach ($logs as $log) {
					if ($ptype == '0') {
						if ($log['types'] != '7') {
							$r .= "<div class='log clearfix' style='font-size:14px;'><div class='left' >你" . $str_arr[$log['types']];
							$r .= "了<a href='http://weibo.com/u/" . $log['touid'] . "' style='color:#FF6600;' target='_blank'>";
							$r .= $log['tonickname'] . "</a>&nbsp;&nbsp;<span style='color:#008000;' class='fbold'>";
						} else {
							$r .= "<div class='log clearfix' style='font-size:14px;'><div class='left' >";
							$r .= "<a href='http://weibo.com/u/" . $log['touid'] . "' style='color:#FF6600;' target='_blank'>";
							$r .= $log['tonickname'] . "</a>" . $str_arr[$log['showtype']] . $str_arr[$log['types']] . "给你，&nbsp;&nbsp;<span style='color:#008000;' class='fbold'>";
						}
						($log['coins'] > 0) ? $log['coins'] = '+' . $log['coins'] . '粉币 ' : $log['coins'] = '';
						($log['points'] > 0) ? $log['points'] = '+' . $log['points'] . '分' : $log['points'] = '';
						$r .= $log['points'] . "&nbsp;&nbsp;" . $log['coins'] . "</span></div><div class='right'><span style='color:#999;font-size:13px;'>" . date('Y-n-j H:i:s', $log['datatime']) . "</span></div></div>";

					} else {
						if ($log['types'] != '6' && $log['types'] != '10' && $log['types'] != '11') {
							$r .= "<div class='log clearfix' style='font-size:14px;'><div class='left'><a href='http://weibo.com/u/" . $log['touid'] . "' style='color:#08C;' target='_blank'>" . $log['tonickname'] . "</a>" . $str_arr[$log['types']];
							$r .= "了你";
						} else {
							if ($log['types'] == '6')	$tip = '返换给';
							if ($log['types'] == '10')	$tip = '用掉';
							if ($log['types'] == '11')	$tip = '给';
							$r .= "<div class='log clearfix' style='font-size:14px;'><div class='left'>你" . $str_arr[$log['showtype']] . $str_arr[$log['types']] . $tip . "<a href='http://weibo.com/u/" . $log['touid'] . "' style='color:#08C;' target='_blank'>" . $log['tonickname'] . "</a>";
							$r .= "";
						}
						($log['coins'] > 0) ? $log['coins'] = '-' . $log['coins'] . '粉币' : $log['coins'] = '';
						($log['points'] > 0) ? $log['points'] = '-' . $log['points'] . '分' : $log['points'] = '';
						$r .= " &nbsp;&nbsp;<span style='color:#ff0000;' class='fbold'>";
						$r .= $log['points'] . "&nbsp;&nbsp;" . $log['coins'] . "</span></div><div class='right'><span style='color:#999;font-size:13px;'>" . date('Y-n-j H:i:s', $log['datatime']) . "</span></div></div>";
					}
				}
				$arr['data']['body']  = $r;
				$arr['data']['count'] = $this->Mwbuser->getlogpage($this->sen_data['wb_id'], $ptype);
				;
			} else {
				$str_arr             = array(
                    '收入',
                    '支出'
                    );
                    $arr['data']['body'] = '只显示最近5天的' . $str_arr[$ptype] . '情况';
			}
		} else {
			$arr['info'] = $logs;
		}

		$this->exitjson($arr);
	}
	//TODO:自动任务
	function myauto()
	{
		$this->chklogin();
		$this->load->model('Mwbuser');
		$query = $this->db->get_where("wtt_autos", array(
            "wb_id" => $this->sen_data['wb_id']
		));
		if ($query->num_rows() > 0) {
			$row      = $query->row_array();
			$is_fauto = $row['isfauto'];
			$is_rauto = $row['israuto'];
			$f_limit  = $row['f_limit'];
			$r_limit  = $row['r_limit'];
			$isgood   = $row['isgood'];
		} else {
			$is_fauto = 0;
			$is_rauto = 0;
			$f_limit  = 30;
			$r_limit  = 20;
			$isgood   = 0;
		}

		$datas = array(
            'is_fauto' => $is_fauto,
            'is_rauto' => $is_rauto,
            'f_limit' => $f_limit,
            'r_limit' => $r_limit,
            'isgood' => $isgood

		);
		$this->db->select('uid,nickname,touid,tonickname,types,datatime,points,paytype,showtype');
		$this->db->from('wtt_pays');
		//$this->db->where('uid',$uid);
		$this->db->where('paytype', 1);
		$this->db->where('(types=3 or types=5)');

		$this->db->order_by('datatime', 'desc');
		$this->db->limit(10, 0);
		$query = $this->db->get();

		$this->data['chongzhi'] = '';
		if ($query->num_rows() > 0) {
			foreach ($query->result_array() as $item) {

				if ($item['types'] == 3) {
					$this->data['chongzhi'] .= '  ' . $item['nickname'] . '<span style=\'color:#008000;\'><b>充值了</b></span><span style=\'color:#ff0000;\'>' . $item['points'] . '</span>积分' . ' <span style=\'color:#cccccc;\'>- ' . date('Y-n-j H:i:s', $item['datatime']) . '</span>';
				} else {
					$this->data['chongzhi'] .= '  ' . $item['nickname'] . '<span style=\'color:#008000;\'>邀请好友</span>' . $item['tonickname'] . '获取<span style=\'color:#ff0000;\'>' . $item['points'] . '</span>积分' . ' <span style=\'color:#cccccc;\'>- ' . date('Y-n-j H:i:s', $item['datatime']) . '</span>';
				}

			}
		}
		$this->myview('myauto_view', $datas, 2);
	}
	function setmyauto()
	{
		$this->chklogin();
		$chkarr = array(
            '点击启动关注',
            '点击关闭关注',
            '点击启动转发',
            '点击关闭转发'
            );
            $act    = trim($this->input->post("autofllows"));
            if (!in_array($act, $chkarr)) {
            	show_error("参数错误", '200', '非法操作');
            	exit;
            }
            $query = $this->db->get_where("wtt_autos", array(
            "wb_id" => $this->sen_data['wb_id']
            ));
            if ($query->num_rows() > 0) {
            	$isupdate = 1;
            } else {
            	$isupdate = 0;
            }
            if ($act == '点击启动关注' || $act == '点击关闭关注') {

            	if ($act == '点击启动关注') {
            		$u_date = array(
                    'isfauto' => 1,
                    'f_limit' => trim($this->input->post('f_timelimit')),
                    'f_uptime' => 0
            		);
            	} else {
            		$u_date = array(
                    'isfauto' => 0
            		);
            	}
            } else {
            	if ($act == '点击启动转发') {
            		$u_date = array(
                    'israuto' => 1,
                    'r_limit' => trim($this->input->post('r_timelimit')),
                    'isgood' => $this->input->post('isgood'),
                    'r_uptime' => 0
            		);
            	} else {
            		$u_date = array(
                    'israuto' => 0
            		);
            	}

            }
            $DB1 = $this->load->database('update', TRUE);
            if ($isupdate == 1) {
            	$DB1->update("wtt_autos", $u_date, array(
                "wb_id" => $this->sen_data['wb_id']
            	));
            } else {
            	$u_date['wb_id'] = $this->sen_data['wb_id'];
            	$DB1->insert("wtt_autos", $u_date);
            }
            redirect('/welcome/myauto');
	}

	//TODO:签到
	function signin()
	{
		$DB1 = $this->load->database('update', TRUE);
		$arr = array(
            "status" => 0,
            "info" => "",
            "data" => ''
            );
            $this->load->model('Mwbuser');
            $w_info = $this->Mwbuser->getinfo($this->sen_data['wb_id'], 'signin');
            if (!empty($w_info)) {
            	$signintime = $w_info['signin'];
            	if (date('y-n-j', $signintime) != date('y-n-j', time())) {        		
            		$this->Mwbuser->sys_give($this->sen_data['wb_id'],0,$this->sen_data['screen_name'],8,$this->data['siteset']['signin_points'],$this->data['siteset']['signin_coins']);
            		$DB1->where('wb_id', $this->sen_data['wb_id']);
            		$DB1->update('wtt_customers', array(
                    'signin' => time()
            		));

            		$this->data['signin'] = time();
            		$arr['status']        = 1;
            		$arr['data']          = $this->data['siteset']['signin_points'];            		
            		$arr['info'] = '签到成功，您获得<span style="color:red;" class="fbold">'.$this->data['siteset']['signin_points'].'</span>积分,<span style="color:red;" class="fbold">'.$this->data['siteset']['signin_coins'].'</span>粉币。分享可获得更多积分';
            		$this->exitjson($arr);
            	} else {
            		$arr['info'] = '今天您已经签到，明天再来吧。分享可获得更多积分';
            	}
            } else {
            	$arr['info'] = '登录超时或用户不存在';
            }
	}

	public function logout()
	{
		$this->session->sess_destroy();
		redirect('welcome');
	}
	private function chklogin()
	{
		if (!$this->session->userdata('wb_userinfo')) {
			redirect('/welcome');
		}
	}
	private function _chekref()
	{
		$ref   = (!isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']);
		$c_url = strtolower(base_url());
		if (FALSE !== strstr(strtolower($ref), $c_url)) {
			return TRUE;
		} else {
			return FALSE;
		}

	}

}
